﻿using System;
using System.Collections.Generic;
using System.Text;

namespace CommonClasses
{
 

class Program
    {
        static void Main(string[] args)
        {
            VMLua.LuaBasedVM vm = new VMLua.LuaBasedVM();


            VMLua.ActiveObject actor = new VMLua.ActiveObject("MP11");
            actor.LuaProgram = @"
-- Important convensions: Main functions of Device is an ActiveObject name and it is device name
-- Coroutine's of device has name '<Device name>co'
-- Such cinvensions allow us to link Lua and C# code througth the Lua's tables
function MP11()
   while(true) do
     print 'Hello World from MP11';
     coroutine.yield();
   end
end;
MP11co=coroutine.create(MP11);
";
            vm.RegisterActiveObject(actor);

            VMLua.ActiveObject actor2 = new VMLua.ActiveObject("mp9c");
            actor2.LuaProgram = @"
-- Important convensions: Main functions of Device is an ActiveObject name and it is device name
-- Coroutine's of device has name '<Device name>co'
-- Such cinvensions allow us to link Lua and C# code througth the Lua's tables
function mp9c()
   while(true) do
     print 'Hello World from mp9c';
     coroutine.yield();
     print (one:Go(dev1:get_State()));
     while(dev1:get_State():get_Count()==0) do
       coroutine.yield();
     end   
   end
end;
mp9cco=coroutine.create(mp9c);
";
            vm.RegisterActiveObject(actor2);

            vm.RegisterObject("one", new GoOne());
            Dispatcher d=(Dispatcher)new Probe();
            vm.RegisterObject("dev1", d);

            for (int i = 0; i < 10; i++)
            {
                vm.ProcessOneStep();
                if (i == 3) ((Probe)d).d.Add("123", 123);
            }
        }
    }

    class GoOne
    {
        public void Go(object i)
        {
            //Console.WriteLine(i);
        }
    }

    class Probe : Dispatcher
    {
        #region IDevice Members
        public Dictionary<string, int>d=new Dictionary<string, int>();
        public IDictionary<string, int> State
        {
            get { return d; }
        }

        public void Reset()
        {
        }

        #endregion
    }

    class DeviceList
    {
        public List<Dispatcher> eqs = new List<Dispatcher>();
    }
}
